<?php
namespace app\admin\model;
use think\Model;
header('Cache-control: private, must-revalidate');

class Article extends Model
{
    //多表查询文章， 获取用户名、分类名
    public function ArticleList()
    {
        return $this->table('article')
            ->alias('a')
            ->join('categorys c','a.category_id = c.id')
            ->join('user u','a.user_id = u.id')
            ->field('a.*,c.classname,u.name')
            ->paginate(10);
    }

    // 单表查询修改方法
    public function oneArt(int $id)
    {
        return $this->table('article')
            ->alias('a')
            ->join('categorys c','a.category_id = c.id')
            ->field('a.*,c.classname')
            ->where('a.id',$id)
            ->find();
    }

    //多表查询文章， 获取用户名、分类名
    public function AtticleKey($id,$key)
    {
        return $this->table('article')
            ->alias('a')
            ->join('categorys c','a.category_id = c.id')
            ->join('user u','a.user_id = u.id')
            ->field('a.*,c.classname,u.name')
            ->where('category_id',$id)
            ->where('title','like','%'.$key.'%')
            ->paginate(10);
    }
}
